class Solution:
    def SqrtX(self, x: int) -> int:
        left, right, ans = 0, x, -1
        while left <= right:
            mid = (left + right) // 2
            if mid * mid <= x:
                ans = mid
                left = mid + 1
            else:
                right = mid - 1
        return ans


ans=Solution()
print(ans.SqrtX(8))

from math import sqrt
def Sqrt2(eps:float=0.1) -> float:
    left, right, mid,mul = 1, 2, 0,0.1
    while mul>eps:
        mid = (left + right) / 2
        if mid*mid >2:
            right=mid
        else:
            left=mid+mul #不加mul-->1.40625,加了则是1.41075
        mul*=0.1 #这里会导致一点误差，可改用decimal解决
    return left

ans=Sqrt2(0.00001)
print("{:.5f}".format(ans))
print("{:.5f}".format(sqrt(2)))